package com.fauks.ndk

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.fauks.ndk.databinding.ActivityFfmpegBinding
import com.fauks.ndk.player.EasyPlayer

/**
 * <pre>
 *     author : slx
 *     time   : 2021/06/29
 *     desc   :
 * </pre>
 */
// RTMP 直播流地址:CCTV6 http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8
class FFmpegActivity : AppCompatActivity() {

    private val player: EasyPlayer by lazy {
        EasyPlayer()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val inflate = ActivityFfmpegBinding.inflate(layoutInflater);

        setContentView(inflate.root)

        player.setDataSource("http://ivi.bupt.edu.cn/hls/cctv6hd.m3u8")
        player.setSurfaceView(inflate.surfaceView)
        player.setOnPrepareListener {
            runOnUiThread {
                Toast.makeText(this, "准备成功，可以开始播放", Toast.LENGTH_SHORT).show()
            }
        }

        inflate.apply {
            btnGetVersion.setOnClickListener {
                btnGetVersion.text = "Version:${player.getVersionInfo()}"
            }

            btnPrepare.setOnClickListener {
                player.prepare()
            }
        }
    }
}